/*
 * VentasDetalleTableModel.java
 *
 * Created on 6 de febrero de 2007, 11:55 AM
 *
 
 */

package inc.jmc.cyberboard.ui.ventas.common;

import inc.jmc.cyberboard.common.NumFormat;
import inc.jmc.cyberboard.ui.ventas.DetalleGridVentas;
import inc.jmc.cyberboard.ui.ventas.VentasFrm;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Juan Miguel Olguin Salguero
 */
public class VentasDetalleTableModel extends DefaultTableModel{
    
    boolean editable=true;
    
    public VentasDetalleTableModel(Object[][] data, Object[] columnNames,boolean editable) 
    {
        super(data,columnNames);
        this.editable = editable;
    }
    public VentasDetalleTableModel(Object[][] data, Object[] columnNames) 
    {
        super(data,columnNames);
        editable=true;
    }
    public VentasDetalleTableModel(Object[][] data, Object[] columnNames,VentasFrm ventasParent) 
    {
        super(data,columnNames);
        editable=true;
        TableModelListener[] listns=this.getTableModelListeners();
        for(int i=0;i<listns.length;++i)
            this.removeTableModelListener(listns[i]);
        this.addTableModelListener(new VentasDetalleModelListener(this,ventasParent));
    }
    public boolean isCellEditable(int row, int col) {
        boolean ret=true;
        if(col==DetalleGridVentas.HEADER_CANTIDAD)
            ret=this.editable;
        else
            ret=false;
        return ret;
    }
    public float getVentaTotal()
    {
        
        int rows=this.getRowCount();
        float retTotal=0;
        for(int i=0;i<rows;++i)
        {
            String montoCelStr=(String)this.getValueAt(i,DetalleGridVentas.HEADER_MONTO);
            //retTotal+=Float.parseFloat(montoCelStr);
            retTotal+=NumFormat.parseMoney(montoCelStr);
        }
        return retTotal;
    
        
    }
    public int getCountArticulos()
    {
        int rows=this.getRowCount();
        int retTotal=0;
        for(int i=0;i<rows;++i)
        {
            String cantidadCelStr=(String)this.getValueAt(i,DetalleGridVentas.HEADER_CANTIDAD);
            retTotal+=Float.parseFloat(cantidadCelStr);
        }
        return retTotal;
    
    }
    
    
}
